package log;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class LogScreen extends MainScreen {

	private VerticalFieldManager vfm;

	public LogScreen() {
		setTitle( "Log screen" );
		vfm = new VerticalFieldManager();
		addMenuItem( new ClearLogMenuItem() );
		for(int i=0; i<Logger.getlogs().size(); i++){
			vfm.add(new LabelField( Logger.getlogs().elementAt(i), Field.FOCUSABLE | Field.USE_ALL_WIDTH ));
		}
		add( vfm );
	}

	private static class ClearLogMenuItem extends MenuItem {
	        public ClearLogMenuItem() {
	            super( "Clear Log", 0, 1 );
	        }
	        public void run() {
	            Logger.clear();
	            UiApplication.getUiApplication().getActiveScreen().deleteAll();
	        }
	    }
}